﻿using BMS.IService;
using BMS.DTO;
using BMS.Entity.RBAC;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace ApiServer.Controllers.Permission
{
    /// <summary>
    /// 权限控制器
    /// </summary>
    [Route("permission")]
    [ApiController]
    public class PermissionController : BaseController<PermissionInfo>
    {
        private readonly IPermissionService permissionService;
        public PermissionController(IPermissionService permissionService) : base(permissionService)
        {
            this.permissionService = permissionService;
        }

        /// <summary>
        /// //查询权限及该子级权限
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// 
        [HttpGet("get")]
        [ApiExplorerSettings(GroupName = "v1")]
        public IActionResult GetPermissionInfo(int Pid)
        {
            return Ok(permissionService.GetPermissionInfo(Pid));
        }
        /// <summary>
        /// 权限的倒序显示+分页+查询
        /// </summary>
        /// <param name="PermissionInfoName"></param>
        /// <param name="Pagesize"></param>
        /// <param name="Pageindex"></param>
        /// <returns></returns>
        /// 
        [HttpGet("ReverseOrder")]
        [ApiExplorerSettings(GroupName = "v1")]
        public IActionResult ReverseOrderShow(int Pagesize, int Pageindex, string? PermissionInfoName="")
        {
            return Ok( permissionService.ReverseOrderShow(Pagesize, Pageindex, PermissionInfoName));
        }

        /// <summary>
        /// 权限的显示+分页+查询
        /// </summary>
        /// <param name="PermissionInfoName"></param>
        /// <param name="Pagesize"></param>
        /// <param name="Pageindex"></param>
        /// <returns></returns>
        /// 
        [HttpGet("show")]
        [ApiExplorerSettings(GroupName = "v1")]
        public IActionResult PermissionInfoShow( int Pagesize, int Pageindex, string? PermissionInfoName="")
        {
            return Ok(permissionService.PermissionInfoShow( Pagesize, Pageindex, PermissionInfoName));
        }


        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// 
        [HttpDelete("luo")]
        [ApiExplorerSettings(GroupName = "v1")]
        public async Task<IActionResult> PermissionDel(int id)
        {
            return Ok(await permissionService.PermissionDel(id));
        }



        /// <summary>
        /// 权限添加
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// 
        [HttpPost("Add")]
        [ApiExplorerSettings(GroupName = "v1")]
        public async Task<IActionResult> PermissionAdd(PermissionAddDto dto)
        {
             return Ok(await permissionService.PermissionAdd(dto));
        }


        /// <summary>
        /// 权限修改
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// 
        [HttpPut("Put")]
        [ApiExplorerSettings(GroupName = "v1")]
        public async Task<IActionResult> PermissionInfoDTO(PermissionAddDto dto)
        {
             return Ok(await permissionService.PermissionInfoDTO(dto));
        }




        /// <summary>
        /// 真.权限删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// 
        [HttpDelete("Delete")]
        [ApiExplorerSettings(GroupName = "v1")]
        public async Task<IActionResult> Delete(int id)
        {
            return Ok(await permissionService.Delete(id));
        }

        /// <summary>
        /// 获取菜单权限
        /// </summary>
        /// <param name="userId">用户ID</param>
        /// <returns></returns>
        [HttpGet("menu")]
        [ApiExplorerSettings(GroupName = "v1")]
        public async Task<IActionResult> GetMenus(int userId)
        {
            return Ok(await permissionService.GetMenus(userId));
        }


        /// <summary>
        /// 权限的批量逻辑删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        /// 
        [HttpDelete("Approval")]
        [ApiExplorerSettings(GroupName = "v1")]
        public async Task<IActionResult> PermissionsSoftDelAll(string idList)
        {
            return Ok(await permissionService.PermissionsSoftDelAll(idList));
        }





    }
}
